package com.bdqn.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * MyBatisConfig
 *
 * @author LILIBO
 * @since 2021-11-25
 */
@EnableTransactionManagement
@Configuration
@MapperScan("com.bdqn.mapper")
public class MyBatisPlusConfig {

    /**
     * 读写分离
     */
    /*@Bean
    public MasterSlaveAutoRoutingPlugin masterSlaveAutoRoutingPlugin() {
        return new MasterSlaveAutoRoutingPlugin();
    }*/

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor().setCountSqlParser(new JsqlParserCountOptimize(true));
    }

    // /**
    //  * 新版本（v3.4.1） 分页插件，一级缓存和二级缓存遵循MyBatis的规则
    //  */
    // @Bean
    // public MybatisPlusInterceptor mybatisPlusInterceptor() {
    //     MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    //     interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
    //     return interceptor;
    // }

    /**
     * 数据权限插件
     */
    /*@Bean
    public DataScopeInterceptor dataScopeInterceptor() {
        return new DataScopeInterceptor();
    }*/

    /**
     * 逻辑删除
     */
    /*@Bean
    public LogicDeleteByIdWithFill sqlInjector() {
        return new LogicDeleteByIdWithFill();
    }*/

}
